
//显示积分对换物品
function gradeGoodsList(){
}

//用户修改密码
function pwdModify(){
	if($.formValidator.pageIsValid('1')){	
		var obj = document.getElementById("passwordForm");
		obj.submit();
	}
}

//创建新密码
function newPassword(){
}

//获取手册
function getManual(){
}

//购物记录查询
function recordList(){
	var startTimeObj = document.getElementById("startTime");
	if($.trim(startTimeObj.value) == ""){
		alert("请选择查询时间！");
		startTimeObj.focus();
		return;
	}	
	var endTimeObj = document.getElementById("endTime");
	if($.trim(endTimeObj.value) == ""){
		alert("请选择查询时间！");
		endTimeObj.focus();
		return;
	}
	var startTime = (startTimeObj.value).replace("-","/");
	var endTime = (endTimeObj.value).replace("-","/");
	dateCompare(startTime,endTime);
	var formObj = document.getElementById("buyedRecordForm");
	formObj.submit();
}
//积分变动列表查询
function gradeList(){
	var startTimeObj = document.getElementById("startTime");
	if($.trim(startTimeObj.value) == ""){
		alert("请选择查询时间！");
		startTimeObj.focus();
		return;
	}	
	var endTimeObj = document.getElementById("endTime");
	if($.trim(endTimeObj.value) == ""){
		alert("请选择查询时间！");
		endTimeObj.focus();
		return;
	}
	var startTime = (startTimeObj.value).replace("-","/");
	var endTime = (endTimeObj.value).replace("-","/");
	dateCompare(startTime,endTime);
	var formObj = document.getElementById("gradeListForm");
	formObj.submit();
}
//手机验证码
function verifyCode(){
}

//通过手机找回密码
function retrievePasswordMobile(){
}

//通过邮件找回密码
function retrievePasswordEmail(){
}

//用户修改信息
function userModify(){
	var nickNameObj = document.getElementById("nickName");
	if($.trim(nickNameObj.value) == ""){
		alert("请输入您的姓名！");
		nickNameObj.focus();
		return;
	}else if(lenReg($.trim(nickNameObj.value)) < 4 ||lenReg($.trim(nickNameObj.value)) > 30){
		alert("您填写的姓名有误！");
		nickNameObj.focus();
		return;
	}
	var sexObj = document.getElementsByName("sex");
	if(sexObj[0].checked == false && sexObj[1].checked == false){
		alert("请选择性别！");
		return;
	}
	var addressObj = document.getElementById("address");
	var isContainNum = false;
	if($.trim(addressObj.value) == ""){
		alert("请填写地址！");
		addressObj.focus();
		return ;
	}else if($.trim(addressObj.value).length < 8){
		alert("您填写的地址有误!");
		addressObj.focus();
		return 
	}else{
		for(var i = 0;i< 10;i++){
			if($.trim(addressObj.value).indexOf(i) >= 0){
				isContainNum = true;
				break;
			}
		}
	}
	if(isContainNum == false){
		alert("您填写的地址有误!");
		addressObj.focus();
		return 
	}
	if($.trim($("#zip").val()) == ""){
		alert("请填写邮政编码！");
		$("#zip")[0].focus();
		return ;
	}else if(!ischeck($.trim($("#zip").val()))){
		alert("邮政编码填写有误！");
		$("#zip")[0].focus();
		return ;
	}
	var mobileObj = document.getElementById("mobile");
	if($.trim(mobileObj.value) == ""){
		alert("请填写手机号码！");
		mobileObj.focus();
		return;
	}else if(!IsMobile($.trim(mobileObj.value))){
		alert("手机号码填写有误！");
		mobileObj.focus();
		return;
	}
	if($.trim($("#email").val()) == ""){
		alert("E-mail地址必须填写！");
		$("#email")[0].focus();
		return;
	}else if(!verifyAddress($.trim($("#email").val()))){
		alert("E-mail地址填写有误！");
		$("#email")[0].focus();
		return;
	}
	var birthYearObj = document.getElementById("birthYear");
	if($.trim(birthYearObj.value) != ""){
		if(!checkNum($.trim(birthYearObj.value))){
			alert("生日输入有误！");
			birthYearObj.focus();
			return;
		}else if($.trim(birthYearObj.value).length != 4){
			alert("年必须是4位数字！");
			birthYearObj.focus();
			return;
		}
	}
	var birthMonthObj = document.getElementById("birthMonth");
	if($.trim(birthMonthObj.value) != ""){
		if(!checkNum($.trim(birthMonthObj.value))){
			alert("生日输入有误！");
			birthMonthObj.focus();
			return;
		}else if($.trim(birthMonthObj.value).length != 2){
			alert("月份必须是2位数字！");
			birthMonthObj.focus();
			return;
		}else{
			if(parseInt($.trim(birthMonthObj.value)) > 12 ||parseInt($.trim(birthMonthObj.value)) < 0){
				alert("月份输入有误！");
				birthMonthObj.focus();
				return;
			}
		}
	}
	var birthDayObj = document.getElementById("birthDay");
	if($.trim(birthDayObj.value) != ""){
		if(!checkNum($.trim(birthDayObj.value))){
			alert("生日输入有误！");
			birthDayObj.focus();
			return;
		}else if($.trim(birthDayObj.value).length != 2){
			alert("日期必须是2位数字！");
			birthDayObj.focus();
			return;
		}else{
			if(parseInt($.trim(birthMonthObj.value)) > 31 ||parseInt($.trim(birthMonthObj.value)) < 0){
				alert("日期输入有误！");
				birthDayObj.focus();
				return;
			}
		}
	}
	var thirdObj = document.getElementById("third");
	if(thirdObj==null || thirdObj.value == ""){
		alert("请选择地区！");
		return;
	}
	var formObj = document.getElementById("userModifyForm");	
	formObj.submit();
}

//订单查询
function orderList(){
	var startTimeObj = document.getElementById("startTime");
	if($.trim(startTimeObj.value) == ""){
		alert("请选择查询时间！");
		startTimeObj.focus();
		return;
	}	
	var endTimeObj = document.getElementById("endTime");
	if($.trim(endTimeObj.value) == ""){
		alert("请选择查询时间！");
		endTimeObj.focus();
		return;
	}
	var startTime = (startTimeObj.value).replace("-","/");
	var endTime = (endTimeObj.value).replace("-","/");
	dateCompare(startTime,endTime);
	var formObj = document.getElementById("form2");
	formObj.submit();
}

//登录
function login(){
	var loginNameObj = document.getElementById("loginName");
	if($.trim(loginNameObj.value) == ""){
		alert("请输入用户名！");
		loginNameObj.focus();
		return;
	}
	var loginPwdObj = document.getElementById("loginPassword");
	if($.trim(loginPwdObj.value) == ""){
		alert("请输入密码！");
		loginPwdObj.focus();
		return;
	}
	var formObj = document.getElementById("loginForm");
	formObj.submit();
}	
 

//注册
function register(){
	var registerUserNameObj = document.getElementById("registerUserName");
		if($.trim(registerUserNameObj.value) == ""){
			document.getElementById("userNameDiv").innerHTML="<img src=images/ico1.gif align=absmiddle /><font color=red>请填写用户名！</font>";
			registerUserNameObj.focus();
			return;
		}else{
			if(!IsMobile($.trim(registerUserNameObj.value)) && !verifyAddress($.trim(registerUserNameObj.value))){
				document.getElementById("userNameDiv").innerHTML="<img src=images/ico1.gif align=absmiddle /><font color=red>用户名必须是手机号码或Email!</font>";
				registerUserNameObj.focus();
				return;
			}else{
				var username=registerUserNameObj.value;
				$.ajax({
				   type: "POST",
				   url: "/check/check-register-username.jspa",
				   data: "checkUsername="+username,
				   success: function(msg){
				   	  if(msg != ""){
					      document.getElementById("userNameDiv").innerHTML="<img src=images/ico1.gif align=absmiddle /><font color=red>"+msg+"</font>";
					      $("#registerUserName")[0].focus();
					      return;
				   	  }else{
						  document.getElementById("userNameDiv").innerHTML="请填写有效的E-mail或手机号作为您的登录帐号";
						  
						  	var registerPasswordObj = document.getElementById("registerPassword");
							if($.trim(registerPasswordObj.value) == ""){
								document.getElementById("passwordDiv").innerHTML="<img src=images/ico1.gif align=absmiddle /><font color=red>请填写密码！</font>";
								registerPasswordObj.focus();
								return;
							}else if($.trim(registerPasswordObj.value).length < 6 || $.trim(registerPasswordObj.value).length > 16){
								document.getElementById("passwordDiv").innerHTML="<img src=images/ico1.gif align=absmiddle /><font color=red>您输入的密码有误！</font>";
								registerPasswordObj.focus();
								return;
							}else{
								document.getElementById("passwordDiv").innerHTML="密码请设为6-16位字母或数字";
							}
							var registerPasswordRepeatObj = document.getElementById("registerPasswordRepeat");
							if($.trim(registerPasswordRepeatObj.value) == ""){
								document.getElementById("passwordDiv2").innerHTML="<img src=images/ico1.gif align=absmiddle /><font color=red>请填写确认密码！</font>";
								registerPasswordRepeatObj.focus();
								return;
							}else if($.trim(registerPasswordRepeatObj.value).length < 6 || $.trim(registerPasswordRepeatObj.value).length > 16){
								document.getElementById("passwordDiv2").innerHTML="<img src=images/ico1.gif align=absmiddle /><font color=red>您输入的确认密码有误！</font>";
								registerPasswordRepeatObj.focus();
								return;
							}else{
								document.getElementById("passwordDiv2").innerHTML="";
							}
							if($.trim(registerPasswordObj.value) != $.trim(registerPasswordRepeatObj.value)){
								document.getElementById("passwordDiv2").innerHTML="<img src=images/ico1.gif align=absmiddle /><font color=red>密码和确认密码不一致！</font>";
								registerPasswordObj.focus();
								return;
							}
							if($.trim(document.getElementById("yjhPassId").value)!="" && $.trim(document.getElementById("rand").value) == ""){
								document.getElementById("checkNumDiv").innerHTML="<img src=images/ico1.gif align=absmiddle /><font color=red>请输入验证码！</font>";
								document.getElementById("introDiv22").style.display="none";
								document.getElementById("rand").focus();
								return ;
							}
							var tiaokuan = document.getElementsByName("tiaokuan");
							for(var i=0;i<tiaokuan.length;i++){
								if(!tiaokuan[i].checked){
									document.getElementById("tiaokuanDiv").innerHTML="<img src=images/ico1.gif align=absmiddle /><font color=red>请接收服务条款！</font>";
									return;
								}
							}
							$.ajaxq("clickqueue",{
						        type: "POST",
						        url: "http://www.yesmywine.com/log/behavior",
						        data: "CUR_DATE=2010-12-14&URL="+window.location+"&TYPE=register&preURL="+cookieUrl,
						        success: function(msg){              
									var formObj = document.getElementById("registerForm");
									formObj.submit();	     
						         }
							});
						  				  
				   	  }
				   }
				})
			}
		}
}
	//检测一个字符串是否全是数字
function checkNum(str){
	str=''+str;
	return str.match(/\D/)==null;
} 


//检测Email格式是否正确
function verifyAddress(email){  
	var pattern = /^([a-zA-Z0-9._-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/; 
 	var flag = pattern.test(email); 
 	if(flag){
 		return true;
 	}
	return false;
}  
//修改送货信息
function modifySendGoodsInfo(){
	
}

//我的订单查询
function myOrderQuery(){
	
}

//购物第二个步骤
function shopping2(){
}

//购物第三个步骤
function shopping3(){
}

//购物第四个步骤
function shopping4(){
}
//日期比较
function dateCompare(str1,str2){
	var d1 = new Date(str1);
	var d2 = new Date(str2);
	if(Date.parse(d1) - Date.parse(d2)>=0){
		alert("时间段选择有误！");
		return;
	}
}
function IsMobile(_str){
    var tmp_str = $.trim(_str);
    var pattern = /1\d{10}/;
    if(pattern.test(tmp_str)){
    	if(tmp_str.length > 11){
    		return false;
    	}else{
    		return true;
    	}
    }else{
    	return false;
    }  
}
function ischeck(postcode){
       if (postcode != "") {   //邮政编码判断
           var pattern = /^[0-9]{6}$/;
           flag = pattern.test(postcode);
		return flag;
       }
}
function lenReg(str){
    return str.replace(/[^\x00-\xFF]/g,'**').length;
 }

//判断用户是否登录
function isLogin(){	
	var html=$.ajax({
			url:"http://www.yesmywine.com/portal/loginState.jspa",
			cache: false,
			async:false
		}).responseText;
	if(html=="0"){
		return false;
	}else if(html=="1"){
		return true;
	}
} 
